<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：因为可以任取数组中的元素，所以就转化成两数相加。先算两个数组的结果
      
      */
      var fourSumCount = function (nums1, nums2, nums3, nums4) {
        let map = new Map()
        for (let i = 0; i < nums1.length; i++) {
          for (let j = 0; j < nums2.length; j++) {
            let sum = nums1[i] + nums2[j]
            if (map.has(sum)) {
              map.set(sum, map.get(sum) + 1)
            } else {
              map.set(sum, 1)
            }
          }
        }
        let res = 0
        //再算nums3和nums4的和
        for (let i = 0; i < nums3.length; i++) {
          for (let j = 0; j < nums4.length; j++) {
            let target = -(nums3[i] + nums4[j])
            if (map.has(target)) {
              res += map.get(target)
            }
          }
        }
        return res
      }
    </script>
  </body>
</html>
